package com.ruoyi.cloudpc.service.impl;

import com.ruoyi.cloudpc.domain.CloudSlideshow;
import com.ruoyi.cloudpc.mapper.CloudSlideshowMapper;
import com.ruoyi.cloudpc.service.ICloudSlideshowService;
import com.ruoyi.common.utils.PicUrlUtil;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 轮播图Service业务层处理
 *
 * @author Ten
 * @date 2025-09-16
 */
@Service
public class CloudSlideshowServiceImpl implements ICloudSlideshowService {
    @Autowired
    private CloudSlideshowMapper cloudSlideshowMapper;
    @Autowired
    private PicUrlUtil picUrlUtil;

    /**
     * 查询轮播图
     *
     * @param id 轮播图主键
     * @return 轮播图
     */
    @Override
    public CloudSlideshow selectCloudSlideshowById(Long id) {
        return cloudSlideshowMapper.selectCloudSlideshowById(id);
    }

    /**
     * 查询轮播图列表
     *
     * @param cloudSlideshow 轮播图
     * @return 轮播图
     */
    @Override
    public List<CloudSlideshow> selectCloudSlideshowList(CloudSlideshow cloudSlideshow) {
        return cloudSlideshowMapper.selectCloudSlideshowList(cloudSlideshow);
    }

    /**
     * 新增轮播图
     *
     * @param cloudSlideshow 轮播图
     * @return 结果
     */
    @Override
    public int insertCloudSlideshow(CloudSlideshow cloudSlideshow) {
        cloudSlideshow.setCreateTime(DateUtils.getNowDate());
        cloudSlideshow.setUrl(picUrlUtil.handlePicUrl(cloudSlideshow.getUrl()));
        return cloudSlideshowMapper.insertCloudSlideshow(cloudSlideshow);
    }

    /**
     * 修改轮播图
     *
     * @param cloudSlideshow 轮播图
     * @return 结果
     */
    @Override
    public int updateCloudSlideshow(CloudSlideshow cloudSlideshow) {
        cloudSlideshow.setUpdateTime(DateUtils.getNowDate());
        cloudSlideshow.setUrl(picUrlUtil.handlePicUrl(cloudSlideshow.getUrl()));
        return cloudSlideshowMapper.updateCloudSlideshow(cloudSlideshow);
    }

    /**
     * 批量删除轮播图
     *
     * @param ids 需要删除的轮播图主键
     * @return 结果
     */
    @Override
    public int deleteCloudSlideshowByIds(Long[] ids) {
        return cloudSlideshowMapper.deleteCloudSlideshowByIds(ids);
    }

    /**
     * 删除轮播图信息
     *
     * @param id 轮播图主键
     * @return 结果
     */
    @Override
    public int deleteCloudSlideshowById(Long id) {
        return cloudSlideshowMapper.deleteCloudSlideshowById(id);
    }
}
